package net.int0r.gscore.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class GStringUtil {
	public static String convertStreamToString(InputStream is) {
		try {
			if (is != null) {
				StringBuilder sb = new StringBuilder();
				String line;

				try {
					BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
					while ((line = reader.readLine()) != null) {
						sb.append(line).append("\n");
					}
				} finally {
					is.close();
				}
				return sb.toString();
			} else {        
				return "";
			}
		}
		catch(Exception ex) {
			return "";
		}
	}

	public static int getId(String url) {
		return Integer.parseInt(url.substring(url.lastIndexOf("/")+1, url.length()));
	}
	
	public static boolean isNullOrBlank(String theStr) {
		if(theStr == null 
				|| theStr.trim().length() == 0)
			return true;
		return false;
	}

}
